<template>
	<view>

		<view class="imgs" v-for="item in img.imgs" :key="item._id">
			<image :src="item.url"></image>

		</view>
		// #ifdef MP-ALIPAY
		<view class="goods-carts">
			<uni-goods-nav :options="options" :fill="true" :button-group="buttonGroup" @click="onClick"
				@buttonClick="buttonClick" />
		</view>
		// #endif
	</view>
</template>
<script setup>
	import {
		storeToRefs
	} from 'pinia'
	import {
		onMounted,
		reactive,
		ref
	} from 'vue'
	import {
		useMemberStore
	} from '@/stores'
	const {
		tradeNo
	} = storeToRefs(useMemberStore())
	const {
		istradeNo
	} = useMemberStore()
	onMounted(() => {
		getimgs()
		console.log(tradeNo)
	})
	let img = reactive({
		imgs: []
	})


	const options = ref([{
		icon: 'chat',
		text: '客服'
	}, {
		icon: 'shop',
		text: '店铺',

		infoBackgroundColor: '#007aff',
		infoColor: "#f5f5f5"
	}])
	let getimgs = () => {
		uni.getStorage({
			key: 'imgs',
			success: function(res) {
				// console.log(typeof res.data,'data')
				img.imgs = JSON.parse(res.data)
			}
		});
		console.log(img.imgs)
	}
	// 12
	const buttonClick = (e) => {
		console.log(e)

		if (e.content.text == "立即购买") {
			uni.getStorage({
				key: 'item',
				success: function(res) {
					let data = JSON.parse(res.data)

					uni.request({
						url: 'http://192.168.137.1:3111/gettradeNo', //仅为示例，并非真实接口地址。
						data: {
							total_amount: data.price,
							subject: data.name
						},
						success: (res) => {
							console.log()
							let tra = res.data.out_trade_no
							my.tradePay({
								// 调用统一收单交易创建接口（alipay.trade.create），获得返回字段支付宝交易号 trade_no
								tradeNO: res.data.result.tradeNo,
								success: res => {
									console.log(res)
									if (res.resultCode == 6001) {
										istradeNo(tra)
										console.log(tradeNo)
										uni.request({
											url: 'http://192.168.137.1:3111/gettradeNo1', //仅为示例，并非真实接口地址。
											data: {
												tra,
												shopname: data.name,
												shopImg: data.img
											},
										})
									}
									if (res.resultCode == 9000) {
										uni.request({
											url: 'http://192.168.137.1:3111/gettradeNo1', //仅为示例，并非真实接口地址。
											data: {
												tra,
												shopname: data.name,
												shopImg: data.img
											},
										})
										uni.navigateTo({
											url: "/pages/paysuccess/paysuccess"
										})
									}
								},
								fail: error => {
									console.log(error)
								},
							});
						}
					});

					// 	else{
					// 		my.tradePay({
					// 			// 调用统一收单交易创建接口（alipay.trade.create），获得返回字段支付宝交易号 trade_no
					// 			tradeNO: tradeNo.value,
					// 			success: res => {
					// 				if (res.resultCode == 6001) {
					// 					console.log(res)
					// 				}
					// 				if (res.resultCode == 9000) {
					// 					console.log(res)
					// 					istradeNo("")

					// 				}
					// 			},
					// 			fail: error => {
					// 				console.log(error)
					// 			},
					// 		});
					// 	}
				}
			});

		}
	}
</script>

<style scoped>
	.imgs {
		width: 760rpx;
		height: 1000rpx;
	}

	image {
		width: 760rpx;
		height: 1000rpx;
	}

	.goods-carts {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 750rpx;
		padding-bottom: calc(env(safe-area-inset-bottom));
		background-color: rgba(red, green, blue, 0);
	}
</style>